/**
 * 
 */
package com.nari.baseinfo.service;

import com.nari.baseinfo.dao.IBuildingDao;
import com.nari.baseinfo.dao.ICommunityDao;
import com.nari.baseinfo.dao.IConcentratorDao;
import com.nari.baseinfo.dao.IHeatMeterDao;
import com.nari.baseinfo.dao.IHeatRoomDao;
import com.nari.baseinfo.dao.IProjectDao;
import com.nari.baseinfo.utils.BaseStatisConstants;
import com.nari.baseinfo.utils.statisentity.BuildingStatisEntity;
import com.nari.baseinfo.utils.statisentity.CommunityStatisEntity;
import com.nari.baseinfo.utils.statisentity.ConcentratorStatisEntity;
import com.nari.baseinfo.utils.statisentity.IGenericStatisEntity;
import com.nari.baseinfo.utils.statisentity.ProjectStatisEntity;
import com.nari.baseinfo.utils.statisentity.RoomStatisEntity;
import com.nari.baseinfo.utils.statisentity.ShareAreaStatisEntity;
import com.nari.heatshare.dao.IAssignMeterDao;
import com.nari.heatshare.dao.ITemperaturePointDao;
import com.nari.sink.dao.ISinkDao;

/**
 * 
 * @author Xiaopeng
 * @date 2013-10-21
 */
public class BaseStatisServiceImpl implements IBaseStatisService {
	private IProjectDao iProjectDao;
	private ICommunityDao iCommunityDao;
	private IBuildingDao iBuildingDao;
	private IHeatRoomDao iHeatRoomDao;
	private IConcentratorDao iConcentratorDao;
	private IHeatMeterDao iHeatMeterDao;
	private IAssignMeterDao iAssignMeterDao;
	private ISinkDao iSinkDao;
	private ITemperaturePointDao iTemperaturePointDao;
	
	/**
	 * 根据统计类型、基础信息ID查询统计实体
	 * @param statisType 统计类型
	 * @param baseUID 基础信息ID
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-10-21
	 */
	public IGenericStatisEntity queryBaseStatisEntity(Integer statisType, 
			String baseUID) throws Exception {
		if(statisType != null) {
			//项目统计
			if(statisType.intValue() == BaseStatisConstants.statisType_projectDetail) {
				return this.queryProjectStatisByID(baseUID);
			}
			//小区统计
			if(statisType.intValue() == BaseStatisConstants.statisType_communityDetail) {
				return this.queryCommunityStatisByID(baseUID);
			}
			//楼栋统计
			if(statisType.intValue() == BaseStatisConstants.statisType_buildingDetail) {
				return this.queryBuildingStatisByID(baseUID);
			}
			//分摊域统计
			if(statisType.intValue() == BaseStatisConstants.statisType_shareAreaDetail) {
				return this.queryShareAreaStatisByID(baseUID);
			}
			//热用户统计
			if(statisType.intValue() == BaseStatisConstants.statisType_roomDetail) {
				return this.queryRoomStatisByID(baseUID);
			}
			//集中器统计
			if(statisType.intValue() == BaseStatisConstants.statisType_concentratorDetail) {
				return this.queryConcentratorStatisByID(baseUID);
			}
		}
		return null;
	}
	
	/**
	 * 通过项目唯一标识查询项目所属统计信息
	 * @param projectUID
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-10-21
	 */
	public ProjectStatisEntity queryProjectStatisByID(String projectUID) throws Exception {
		ProjectStatisEntity projectStatis = new ProjectStatisEntity();
		//小区个数统计
		int communitySum = iCommunityDao.countCommunitySumByBelongs(null, null, null, projectUID);
		projectStatis.setCommunitySum(communitySum);
		//楼栋个数统计
		int buildingSum = iBuildingDao.countBuildingSumByBelongs(projectUID, null);
		projectStatis.setBuildingSum(buildingSum);
		//热用户个数统计
		int heatRoomSum = iHeatRoomDao.countRoomSumByBelongs(projectUID, null, null, null, null);
		projectStatis.setHeatRoomSum(heatRoomSum);
		//总供热面积统计
		double roomHeatAreaSum = iHeatRoomDao.sumRoomStructAreaByBelongs(projectUID, null, null, null, null);
		projectStatis.setRoomHeatAreaSum(roomHeatAreaSum);
		//集中器个数统计
		int concentratorSum = iConcentratorDao.countConcentratorSumByBelongs(projectUID, null);
		projectStatis.setConcentratorSum(concentratorSum);
		//热量表个数统计
		int heatMeterSum = iHeatMeterDao.countMeterSumByBelongs(projectUID, null, null, null);
		projectStatis.setHeatMeterSum(heatMeterSum);
		//分配表个数统计
		int assignMeterSum = iAssignMeterDao.countMeterSumByBelongs(projectUID, null, null, null);
		projectStatis.setAssignMeterSum(assignMeterSum);
		//散热器个数统计
		int heatSinkerSum = iSinkDao.countSinkerSumByBelongs(projectUID, null, null, null);
		projectStatis.setHeatSinkerSum(heatSinkerSum);
		//温度点个数统计
		int tempPointSum = iTemperaturePointDao.countTempPointSumByBelongs(projectUID, null, null, null);
		projectStatis.setTempPointSum(tempPointSum);
		return projectStatis;
	}
	
	/**
	 * 根据小区唯一标识查询小区所属统计信息
	 * @param communityUID
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-10-23
	 */
	public CommunityStatisEntity queryCommunityStatisByID(String communityUID) throws Exception {
		CommunityStatisEntity communityStatis = new CommunityStatisEntity();
		//楼栋个数统计
		int buildingSum = iBuildingDao.countBuildingSumByBelongs(null, communityUID);
		communityStatis.setBuildingSum(buildingSum);
		//热用户个数统计
		int heatRoomSum = iHeatRoomDao.countRoomSumByBelongs(null, communityUID, null, null, null);
		communityStatis.setHeatRoomSum(heatRoomSum);
		//总供热面积统计
		double roomHeatAreaSum = iHeatRoomDao.sumRoomStructAreaByBelongs(null, communityUID, null, null, null);
		communityStatis.setRoomHeatAreaSum(roomHeatAreaSum);
		//集中器个数统计
		int concentratorSum = iConcentratorDao.countConcentratorSumByBelongs(null, communityUID);
		communityStatis.setConcentratorSum(concentratorSum);
		//热量表个数统计
		int heatMeterSum = iHeatMeterDao.countMeterSumByBelongs(null, communityUID, null, null);
		communityStatis.setHeatMeterSum(heatMeterSum);
		//分配表个数统计
		int assignMeterSum = iAssignMeterDao.countMeterSumByBelongs(null, communityUID, null, null);
		communityStatis.setAssignMeterSum(assignMeterSum);
		//散热器个数统计
		int heatSinkerSum = iSinkDao.countSinkerSumByBelongs(null, communityUID, null, null);
		communityStatis.setHeatSinkerSum(heatSinkerSum);
		//温度点个数统计
		int tempPointSum = iTemperaturePointDao.countTempPointSumByBelongs(null, communityUID, null, null);
		communityStatis.setTempPointSum(tempPointSum);
		return communityStatis;
	}
	
	/**
	 * 根据楼栋唯一标识查询楼栋所属统计信息
	 * @param buildingUID
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-10-23
	 */
	public BuildingStatisEntity queryBuildingStatisByID(String buildingUID) throws Exception {
		BuildingStatisEntity buildingStatis = new BuildingStatisEntity();
		//热用户个数统计
		int heatRoomSum = iHeatRoomDao.countRoomSumByBelongs(null, null, buildingUID, null, null);
		buildingStatis.setHeatRoomSum(heatRoomSum);
		//总供热面积统计
		double roomHeatAreaSum = iHeatRoomDao.sumRoomStructAreaByBelongs(null, null, buildingUID, null, null);
		buildingStatis.setRoomHeatAreaSum(roomHeatAreaSum);
		//分配表个数统计
		int assignMeterSum = iAssignMeterDao.countMeterSumByBelongs(null, null, buildingUID, null);
		buildingStatis.setAssignMeterSum(assignMeterSum);
		//散热器个数统计
		int heatSinkerSum = iSinkDao.countSinkerSumByBelongs(null, null, buildingUID, null);
		buildingStatis.setHeatSinkerSum(heatSinkerSum);
		//温度点个数统计
		int tempPointSum = iTemperaturePointDao.countTempPointSumByBelongs(null, null, buildingUID, null);
		buildingStatis.setTempPointSum(tempPointSum);
		return buildingStatis;
	}
	
	/**
	 * 根据分摊域唯一标识查询分摊域所属统计信息
	 * @param shareAreaUID
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-10-23
	 */
	public ShareAreaStatisEntity queryShareAreaStatisByID(String shareAreaUID) throws Exception {
		ShareAreaStatisEntity areaStatis = new ShareAreaStatisEntity();
		//热用户个数统计
		int heatRoomSum = iHeatRoomDao.countRoomSumByBelongs(null, null, null, shareAreaUID, null);
		areaStatis.setHeatRoomSum(heatRoomSum);
		//总供热面积统计
		double roomHeatAreaSum = iHeatRoomDao.sumRoomStructAreaByBelongs(null, null, null, shareAreaUID, null);
		areaStatis.setRoomHeatAreaSum(roomHeatAreaSum);
		//热量表个数统计
		int heatMeterSum = iHeatMeterDao.countMeterSumByBelongs(null, null, null, shareAreaUID);
		areaStatis.setHeatMeterSum(heatMeterSum);
		return areaStatis;
	}
	
	/**
	 * 根据热用户唯一标识查询热用户所属统计信息
	 * @param heatRoomUID
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-10-23
	 */
	public RoomStatisEntity queryRoomStatisByID(String heatRoomUID) throws Exception {
		RoomStatisEntity roomStatis = new RoomStatisEntity();
		//分配表个数统计
		int assignMeterSum = iAssignMeterDao.countMeterSumByBelongs(null, null, null, heatRoomUID);
		roomStatis.setAssignMeterSum(assignMeterSum);
		//散热器个数统计
		int heatSinkerSum = iSinkDao.countSinkerSumByBelongs(null, null, null, heatRoomUID);
		roomStatis.setHeatSinkerSum(heatSinkerSum);
		return roomStatis;
	}
	
	/**
	 * 根据集中器唯一标识查询热用户所属统计信息
	 * @param concentratorUID
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-3-17
	 */
	public ConcentratorStatisEntity queryConcentratorStatisByID(String concentratorUID) throws Exception {
		ConcentratorStatisEntity concentratorStatis = new ConcentratorStatisEntity();
		//分配表个数统计
		int assignMeterSum = iAssignMeterDao.countMeterSumByConcentratorID(concentratorUID);
		concentratorStatis.setAssignMeterSum(assignMeterSum);
		//温度点个数统计
		int tempPointSum = iTemperaturePointDao.countTempPointSumByBelongs(null, null, null, concentratorUID);
		concentratorStatis.setTempPointSum(tempPointSum);
		return concentratorStatis;
	}

	/**
	 * @return the iProjectDao
	 */
	public IProjectDao getiProjectDao() {
		return iProjectDao;
	}

	/**
	 * @param iProjectDao the iProjectDao to set
	 */
	public void setiProjectDao(IProjectDao iProjectDao) {
		this.iProjectDao = iProjectDao;
	}

	/**
	 * @return the iCommunityDao
	 */
	public ICommunityDao getiCommunityDao() {
		return iCommunityDao;
	}

	/**
	 * @param iCommunityDao the iCommunityDao to set
	 */
	public void setiCommunityDao(ICommunityDao iCommunityDao) {
		this.iCommunityDao = iCommunityDao;
	}

	/**
	 * @return the iBuildingDao
	 */
	public IBuildingDao getiBuildingDao() {
		return iBuildingDao;
	}

	/**
	 * @param iBuildingDao the iBuildingDao to set
	 */
	public void setiBuildingDao(IBuildingDao iBuildingDao) {
		this.iBuildingDao = iBuildingDao;
	}

	/**
	 * @return the iHeatRoomDao
	 */
	public IHeatRoomDao getiHeatRoomDao() {
		return iHeatRoomDao;
	}

	/**
	 * @param iHeatRoomDao the iHeatRoomDao to set
	 */
	public void setiHeatRoomDao(IHeatRoomDao iHeatRoomDao) {
		this.iHeatRoomDao = iHeatRoomDao;
	}

	/**
	 * @return the iConcentratorDao
	 */
	public IConcentratorDao getiConcentratorDao() {
		return iConcentratorDao;
	}

	/**
	 * @param iConcentratorDao the iConcentratorDao to set
	 */
	public void setiConcentratorDao(IConcentratorDao iConcentratorDao) {
		this.iConcentratorDao = iConcentratorDao;
	}

	/**
	 * @return the iHeatMeterDao
	 */
	public IHeatMeterDao getiHeatMeterDao() {
		return iHeatMeterDao;
	}

	/**
	 * @param iHeatMeterDao the iHeatMeterDao to set
	 */
	public void setiHeatMeterDao(IHeatMeterDao iHeatMeterDao) {
		this.iHeatMeterDao = iHeatMeterDao;
	}

	/**
	 * @return the iAssignMeterDao
	 */
	public IAssignMeterDao getiAssignMeterDao() {
		return iAssignMeterDao;
	}

	/**
	 * @param iAssignMeterDao the iAssignMeterDao to set
	 */
	public void setiAssignMeterDao(IAssignMeterDao iAssignMeterDao) {
		this.iAssignMeterDao = iAssignMeterDao;
	}

	/**
	 * @return the iSinkDao
	 */
	public ISinkDao getiSinkDao() {
		return iSinkDao;
	}

	/**
	 * @param iSinkDao the iSinkDao to set
	 */
	public void setiSinkDao(ISinkDao iSinkDao) {
		this.iSinkDao = iSinkDao;
	}

	/**
	 * @return the iTemperaturePointDao
	 */
	public ITemperaturePointDao getiTemperaturePointDao() {
		return iTemperaturePointDao;
	}

	/**
	 * @param iTemperaturePointDao the iTemperaturePointDao to set
	 */
	public void setiTemperaturePointDao(ITemperaturePointDao iTemperaturePointDao) {
		this.iTemperaturePointDao = iTemperaturePointDao;
	}
	
}
